using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Media;

namespace WPFUtilities
{
    public class DepthFirstVisualTreeIterator : VisualTreeIterator
    {
        public override IEnumerable<DependencyObject> GetNodes(DependencyObject root)
        {
            yield return root;
            for (int i = 0; i < VisualTreeHelper.GetChildrenCount(root); i++)
            {
                DependencyObject child = VisualTreeHelper.GetChild(root, i);
                foreach (DependencyObject grandChild in GetNodes(child))
                {
                    yield return grandChild;
                }
            }
        }
    }
}
